const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

// Create multiple instances
const extractCSS = new ExtractTextPlugin('[name]-one.css');
const extractLESS = new ExtractTextPlugin('[name]-two.css');

// const css_loader = "css-loader?modules&localIdentName=[path][name]---[local]---[hash:base64:5]"
const css_loader = "css-loader?modules&localIdentName=[path][name]---[local]";

const webpackConfig = {
    entry: path.resolve(__dirname, './src/index.js'),//这里也可以直接写index.1.less，但是也会生成一个js文件
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'index.bundle.js'
    },
    module: {
        loaders: [
            {
                test: /\.json$/,
                loader: 'json-loader',
            },
            {
                test: /\.less$/,
                loaders: ['style-loader', css_loader, 'less-loader'],//1.x的版本是不需要加 "-loader"的，现在用的是3.x版本，需要加
            },
            {
                test: /\.jsx?$/,
                loader: 'babel-loader',
                exclude: [/node_modules/, './www/comm/public'],
            }
        ],

        rules: [
            {
                test: /\.less$/i,
                use: extractCSS.extract([css_loader, 'less-loader'])
            },
            //没有这里的配置，只有上面的loader，会报错的，这个跟webpack1.x的配置方法不一样
            {
                test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['react']
                    }
                }
            }
        ],
    },
    plugins: [
        extractCSS, extractLESS
    ],
}


module.exports = webpackConfig;
